<?php

class LMSRequestModel
{
    private $mConnection;
    private $mDatabase;
	private $mQuery;
	private $mResult;
	
	function __construct()
	{
		//initialization can be done here
		$this->mConnection = null;
    	$this->mDatabase = null;
	 	$this->mQuery = null;
	 	$this->mResult = null;
	}
	
	/** method or function name
	* description
	* parameters 
	* return type
	*/
	
    public function connectDatabase()
    {
		$this->mConnection = mysql_connect("localhost", "root", "") or die ("could not connect");
		$this->mDatabase = mysql_select_db("lms_database", $this->mConnection) or die("could not connect with database");
    }
	
	public function getLibraryBooksModel()
	{
		$this->connectDatabase();
		$this->mQuery = "SELECT * FROM lms_library_books_table";
		$this->mResult = mysql_query($this->mQuery) or die("could not get data from table");
		return $this->mResult;
	}
	
	public function updateLibraryBooksModel($data)
	{   
		$this->connectDatabase();
		$this->mQuery = "SELECT AvailableCopies FROM lms_library_books_table WHERE bookID=".$data;
		$this->mResult = mysql_query($this->mQuery) or die("could not get data from table");
		if($availableBooks = mysql_result($this->mResult,0))
		{
			$this->mQuery = "UPDATE lms_library_books_table SET AvailableCopies=".--$availableBooks." WHERE bookID=".$data;
			$this->mResult = mysql_query($this->mQuery) or die("could not get data from table");
			echo "<center><h1>BOOK REQUEST IS SUCCESSFUL</h1></center>";
		}
	}
}